﻿'
' Quiz Module for DotNetNuke
' Project Contributors - Will Strohl (http://www.WillStrohl.com)
'
'Copyright (c) 2011, Will Strohl
'All rights reserved.
'
'Redistribution and use in source and binary forms, with or without modification, are 
'permitted provided that the following conditions are met:
'
'Redistributions of source code must retain the above copyright notice, this list of 
'conditions and the following disclaimer.
'
'Redistributions in binary form must reproduce the above copyright notice, this list 
'of conditions and the following disclaimer in the documentation and/or other 
'materials provided with the distribution.
'
'Neither the name of Quiz Module for DotNetNuke, nor the names of its contributors may be 
'used to endorse or promote products derived from this software without specific prior 
'written permission.
'
'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
'EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
'OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
'SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
'INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
'TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
'BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
'CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
'ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 
'DAMAGE.
'

Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Exceptions
Imports System.Data
Imports WillStrohl.Modules.Quiz.QuizInfoMembers

Namespace WillStrohl.Modules.Quiz

    <Serializable()> _
    Public NotInheritable Class QuestionInfo
        Implements IQuestionInfo, IHydratable
        
#Region " Private Members "

        Private p_DisplayOrder As Integer = Null.NullInteger
        Private p_IsActive As Boolean = Null.NullBoolean
        Private p_LastModifiedBy As Integer = Null.NullInteger
        Private p_LastModifiedDate As DateTime = Null.NullDate
        Private p_RandomizeAnswers As Boolean = Null.NullBoolean
        Private p_Question As String = Null.NullString
        Private p_QuestionId As Integer = Null.NullInteger
        Private p_QuestionType As String = Null.NullString
        Private p_QuizId As Integer = Null.NullInteger

#End Region

#Region " Public Properties "

        Public Property DisplayOrder As Integer Implements IQuestionInfo.DisplayOrder
            Get
                Return p_DisplayOrder
            End Get
            Set(value As Integer)
                p_DisplayOrder = value
            End Set
        End Property

        Public Property IsActive As Boolean Implements IQuestionInfo.IsActive
            Get
                Return p_IsActive
            End Get
            Set(value As Boolean)
                p_IsActive = value
            End Set
        End Property

        Public Property LastModifiedBy As Integer Implements IQuestionInfo.LastModifiedBy
            Get
                Return p_LastModifiedBy
            End Get
            Set(value As Integer)
                p_LastModifiedBy = value
            End Set
        End Property

        Public Property LastModifiedDate As Date Implements IQuestionInfo.LastModifiedDate
            Get
                Return p_LastModifiedDate
            End Get
            Set(value As Date)
                p_LastModifiedDate = value
            End Set
        End Property

        Public Property Question As String Implements IQuestionInfo.Question
            Get
                Return p_Question
            End Get
            Set(value As String)
                p_Question = value
            End Set
        End Property

        Public Property QuestionId As Integer Implements IQuestionInfo.QuestionId
            Get
                Return p_QuestionId
            End Get
            Set(value As Integer)
                p_QuestionId = value
            End Set
        End Property

        Public Property QuestionType As String Implements IQuestionInfo.QuestionType
            Get
                Return p_QuestionType
            End Get
            Set(value As String)
                p_QuestionType = value
            End Set
        End Property

        Public Property QuizId As Integer Implements IQuestionInfo.QuizId
            Get
                Return p_QuizId
            End Get
            Set(value As Integer)
                p_QuizId = value
            End Set
        End Property

        Public Property RandomizeAnswers As Boolean Implements IQuestionInfo.RandomizeAnswers
            Get
                Return p_RandomizeAnswers
            End Get
            Set(value As Boolean)
                p_RandomizeAnswers = value
            End Set
        End Property

#End Region

        Public Sub New()
            ' do nothing
        End Sub

#Region " IHydratable Implementation "

        Public Property KeyID() As Integer Implements IHydratable.KeyID
            Get
                Return p_QuestionId
            End Get
            Set(ByVal value As Integer)
                p_QuestionId = value
            End Set
        End Property

        Public Sub Fill(ByVal dr As IDataReader) Implements IHydratable.Fill
            Try
                While dr.Read
                    If Not dr.Item(DISPLAY_ORDER_FIELD) Is Nothing Then
                        p_DisplayOrder = Integer.Parse(dr.Item(DISPLAY_ORDER_FIELD).ToString, Globalization.NumberStyles.Integer)
                    End If
                    If Not dr.Item(IS_ACTIVE_FIELD) Is Nothing Then
                        p_IsActive = Boolean.Parse(dr.Item(IS_ACTIVE_FIELD).ToString)
                    End If
                    If Not dr.Item(LAST_MODIFIED_BY_FIELD) Is Nothing Then
                        p_LastModifiedBy = Integer.Parse(dr.Item(LAST_MODIFIED_BY_FIELD).ToString, Globalization.NumberStyles.Integer)
                    End If
                    If Not dr.Item(LAST_MODIFIED_DATE_FIELD) Is Nothing Then
                        p_LastModifiedDate = DateTime.Parse(dr.Item(LAST_MODIFIED_DATE_FIELD).ToString)
                    End If
                    If Not dr.Item(RANDOMIZE_ANSWERS_FIELD) Is Nothing Then
                        p_RandomizeAnswers = Boolean.Parse(dr.Item(RANDOMIZE_ANSWERS_FIELD).ToString)
                    End If
                    If Not dr.Item(QUESTION_FIELD) Is Nothing Then
                        p_Question = dr.Item(QUESTION_FIELD).ToString
                    End If
                    If Not dr.Item(QUESTION_ID_FIELD) Is Nothing Then
                        p_QuestionId = Integer.Parse(dr.Item(QUESTION_ID_FIELD).ToString(), Globalization.NumberStyles.Integer)
                    End If
                    If Not dr.Item(QUESTION_TYPE_FIELD) Is Nothing Then
                        p_QuestionType = dr.Item(QUESTION_TYPE_FIELD).ToString()
                    End If
                    If Not dr.Item(QUIZ_ID_FIELD) Is Nothing Then
                        p_QuizId = Integer.Parse(dr.Item(QUIZ_ID_FIELD).ToString(), Globalization.NumberStyles.Integer)
                    End If
                End While
            Catch ex As Exception
                LogException(ex)
            Finally
                If Not dr.IsClosed Then
                    dr.Close()
                End If
            End Try
        End Sub

#End Region

    End Class

End Namespace